<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字典明细管理</title>
    <#-- 使用相对当前模板文件的路径 再去找另一个模板文件 -->
    <#include "/common/link.ftl">


</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--定义一个变量  菜单回显-->
    <#assign currentMenu="systemDictionaryItem"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>字典明细管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row" style="margin:20px">
                    <div class="col-xs-2">
                        <div class="panel panel-default">
                            <div class="panel-heading">字典目录</div>
                            <div class="panel-body">
                                <div class="list-group" id="dic">
                                    <#list sdis as s>
                                        <a href="/systemDictionaryItem/list?typeId=${s.id}"
                                           class="list-group-item ${(s.id==qo.typeId)?string('active','')}">${s.title}</a>
                                    </#list>

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-10">
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <input type="hidden" name="typeId" id="type" value="${qo.typeId}">
                            <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>字典明细标题</th>
                                    <th>字典明细序号</th>
                                    <th>上级明细</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <#list pageInfo.list as p>
                                    <tr>
                                        <td>${p_index+1}</td>
                                        <td>
                                            <a href="/systemDictionaryItem/list?parentId=${p.id}">${p.title}</a>
                                        </td>
                                        <td>${p.sequence}</td>
                                        <td>${p.parent.title!'无'}</td>
                                        <td>
                                            <a href="#" class="btn btn-info btn-xs btn-input">
                                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                                            </a>
                                        </td>
                                    </tr>
                                </#list>
                                </tbody>

                            </table>
                            <#include "/common/page.ftl" >
                        </div>
                    </div>
                </div>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl" >
</div>


<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate" method="post" id="editForm">
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">字典目录：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="sdi" name="type.id">
                                <option value="">请选择目录</option>
                                <#list sdis as p>
                                    <option value="${p.id}">${p.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">上级明细：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="parent.id" id="parent">
                                <option value="">无</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">明细标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sn"
                                   placeholder="请输入字典明细编码">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">明细序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequen"
                                   placeholder="请输入字典明细序号">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    //给编辑按钮绑定一个点击事件
    $('.btn-input').click(function () {
        $('#editModal').modal('show')
    });


    //目录下拉框的值改变事件

    $('#sdi').change(function () {
        //获取选中的值,谁调用他this就是谁
        console.log(this);
        let val = $(this).val();
        console.log(val);
        //发送AJAX获取明细数据
        $.get('/systemDictionaryItem/selectByTypeId', {id: val}, function (data) {
            console.log(111);
            let str = '<option value="">无</option>';
            $.each(data, function (index, ele) {
                str += '<option value="' + ele.id + '">' + ele.title + '</option>'
            });
            //等同于拿到$("#parent").append('子元素')
            $("#parent").html(str)
        })
    })
</script>

</body>
</html>
